<template>
  <div class="banner">

    <swiper ref="mySwiper" :options="swiperOptions" v-if="banners.length > 0">
      <swiper-slide v-for="banner in banners" :key="banner.bannerId" class="item">
        <a :href="banner.url">
          <img :src="banner.pic" :alt="banner.typeTitle">
        </a>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>

import {swiper, swiperSlide} from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'

export default {
  props: {
    banners: Array
  },
  name: "Banner",
  components: {
    swiper,
    swiperSlide
  },
  data() {
    return {
      swiperOptions: {
        loop: true,                   //循环模式
        autoplay: {
          delay: 3000,                //每间隔一秒钟跳转一张
          stopOnLastSlide: false,     //当切换到最后一个slide时停止自动切换
          disableOnInteraction: false //用户操作swiper之后,是否禁止autoplay
        },
        //需要分页器
        pagination: {
          el: '.swiper-pagination'
        },
        //告诉 swiper 数据是异步加载的, 数据更新后需要重新加载内容
        observer: true,
        observeParents: true,
        observeSlideChildren: true
      }
    }
  },
}
</script>

<style scoped lang="scss">
.banner {
  .item {
    img {
      width: 100%;
      height: 300px;
    }
  }
}
</style>
<style lang="scss">
@import "../../assets/css/variable";
@import "../../assets/css/mixin";

.banner {
  .swiper-pagination-bullet {
    width: 16px;
    height: 16px;
    background: #fff;
    opacity: 1;
  }

  .swiper-pagination-bullet-active {
    @include bullet_active_color()
  }
}
</style>
